package roborally.model;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

@Value
public class Energy implements Comparable<Energy> {
	
	public Energy(double ws){
		this.ws = ws;
	}
	
	private double getWs(){
		return ws;
	}
	
	public double getValueIn(Energy.Unit unit){
		return unit.getValue(getWs());
	}
	
	public enum Unit {
		WS{

			@Override
			public double getValue(double ws) {
				return ws;
			}
			
		},
		KJ{

			@Override
			public double getValue(double ws) {
				return ws/1000.0;
			}
			
		},
		J{

			@Override
			public double getValue(double ws) {
				return ws;
			}
			
		};
		public abstract double getValue(double ws);
	}
	
	private double ws;

	@Override
	public int compareTo(Energy arg0) {
		return Double.compare(getWs(), arg0.getValueIn(Unit.WS));
	}
	
	@Override
	public String toString() {
		return Double.toString(ws);
	}
	
	@Override
	public boolean equals(Object o) {
		if(!this.getClass().isAssignableFrom(o.getClass())) return false;
		return this.hashCode() == o.hashCode();
	}
	
	@Override
	public int hashCode(){
		return Integer.valueOf(toString());
	}
	
}
